import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { BasicItemEntity } from "./basic-item.entity";

@Entity("character_medicine")
@ManualTimestamp()
export class CharacterMedicineEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "characterId", comment: "角色ID" })
  characterId!: number;

  @Column("int", { name: "itemId", comment: "药品ID" })
  itemId!: number;

  @Column("int", { default: 1, comment: "药品数量" })
  num!: number;

  @Column("int", {
    default: 1,
    comment: "药品状态：1-正常，0-已使用，-1-已丢弃" })
  status!: number;

  @Column("int", { default: 0, comment: "是否绑定：0-不绑定，1-绑定" })
  isBound!: number;

  @Column("varchar", { length: 100, nullable: true, comment: "药品名称" })
  name!: string;

  @Column("varchar", { length: 100, nullable: true, comment: "药品图片" })
  pic!: string;

  @Column("varchar", { length: 500, nullable: true, comment: "药品描述" })
  description!: string;

  @Column("int", { default: 1, comment: "药品类型：1-药品" })
  itemType!: number;

  @Column("int", { default: 0, comment: "药品稀有度" })
  rarity!: number;

  @Column("int", { default: 1, comment: "药品等级" })
  level!: number;

  @Column("datetime", { comment: "获得时间" })
  obtainedAt!: Date;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", comment: "更新时间", nullable: true })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;

  @ManyToOne(() => BasicItemEntity)
  @JoinColumn({ name: "itemId" })
  basicItem!: BasicItemEntity;
}
